import os

# home = os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd())))
# home = "./"
acts = "./"
acts_test_suite_list = [
    "ohos_moduletest_suite",
    "ohos_hap_suite",
    "ohos_js_hap_suite",
    "ohos_js_app_suite",
    "pythontest_suite",
    "js_hap_suite",
    "ohos_hap_assist_suite",
    "ohos_app_assist_suite"
]

part_name_list = [
    "part_name"
]

def is_contain_text(file_path, text_list):
    try:
        with open(file_path, 'r') as file:
            content = file.read()
            for text in text_list:
                if text in content:
                    return True
        return False
    except FileNotFoundError:
        print("文件未找到")

def run(path):
    count_all = 0
    count_pass = 0
    # 遍历目录下的所有文件和子目录
    no_partname_build_list = []
    normal_build_list = []
    for root, dirs, files in os.walk(path):
        for file in files:
            if file == 'BUILD.gn':
                file_path = os.path.join(root, file)
                if is_contain_text(file_path,acts_test_suite_list):
                    count_all += 1
                    if is_contain_text(file_path, part_name_list):
                        count_pass += 1
                        normal_build_list.append(file_path)
                    else:
                        no_partname_build_list.append(file_path);
    print(count_all)
    print(count_pass)
    with open("no_partname_build.txt", 'w') as file:
        for item in no_partname_build_list:
            file.write(str(item) + '\n')
    with open("normal_build_list.txt", 'w') as file:
        for item in normal_build_list:
            file.write(str(item) + '\n')
    print("写入成功")


if __name__ == '__main__':
    run(acts)